//
//  MemberWelfareSecondView.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/30.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "MemberWelfareSecondView.h"
#import "MemberWelfareSecondTableViewCell.h"
#import "MemberWelfareSecondLastTableViewCell.h"
#import "MemberVModel.h"
static NSString *interestsCellID = @"interestsCellID";
static NSString *interestsLastCellID = @"interestsLastCellID";

@interface MemberWelfareSecondView () <UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) UITableView *memberInterestsTableView;

@property (strong, nonatomic) NSArray *contentArr;

@end

@implementation MemberWelfareSecondView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self addSubview:self.memberInterestsTableView];
        
        __weak typeof(self) weakSelf = self;
        [self.memberInterestsTableView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(weakSelf.mas_left);
            make.right.mas_equalTo(weakSelf.mas_right);
            make.top.mas_equalTo(weakSelf.mas_top);
            make.bottom.mas_equalTo(weakSelf.mas_bottom);
            
        }];
    }
    
    return self;
}


- (void)reloadArray:(NSArray *)array {
    
    self.contentArr = array;
    __weak __typeof(self) weakself= self;
    dispatch_async(dispatch_get_main_queue(), ^{
        [weakself.memberInterestsTableView reloadData];
    });
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return jisuan(288);
}

#pragma mark -delegate \ datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.contentArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MemberVModel *model = self.contentArr[indexPath.row];
    MemberWelfareSecondTableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:interestsCellID];
    MemberWelfareSecondLastTableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:interestsLastCellID];
    
    
    if ([model.type intValue]==1) {
        cell1.selectionStyle = UITableViewCellSelectionStyleNone;
        cell1.twoModel = model;
            return cell1;
    }else {
        cell2.selectionStyle = UITableViewCellSelectionStyleNone;
        cell2.oneModel = model;
            return cell2;
    }
  
}


#pragma mark -lazy
- (UITableView *)memberInterestsTableView {
    
    if (!_memberInterestsTableView) {
        
        _memberInterestsTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        
        _memberInterestsTableView.delegate = self;
        _memberInterestsTableView.dataSource = self;
        
        _memberInterestsTableView.scrollEnabled = NO;
        
        _memberInterestsTableView.estimatedRowHeight = 0;
        _memberInterestsTableView.estimatedSectionFooterHeight = 0;
        _memberInterestsTableView.estimatedSectionHeaderHeight = 0;
        
        _memberInterestsTableView.showsVerticalScrollIndicator = NO;
        _memberInterestsTableView.showsHorizontalScrollIndicator = NO;

        [_memberInterestsTableView registerClass:[MemberWelfareSecondTableViewCell class] forCellReuseIdentifier:interestsCellID];
         [_memberInterestsTableView registerClass:[MemberWelfareSecondLastTableViewCell class] forCellReuseIdentifier:interestsLastCellID];
        _memberInterestsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        if (@available(iOS 11.0, *)) {
            
            _memberInterestsTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        
        
    }
    
    return _memberInterestsTableView;
    
}

 
@end
